<template>
  <div class="main">
    <el-row :gutter="20">
      <el-col :span="24">
        <div class="grid-content bg-purple">
          <p class="wen">文章管理</p>
          <el-table
            ref="multipleTable"
            :data="list"
            @selection-change="handleSelectionChange"
          >
            <el-table-column type="selection" label="选择" />

            <el-table-column property="title" label="标题" />
            <el-table-column
              property="pic"
              label="封面"
              show-overflow-tooltip
              width="280"
              ><div class="imgUrl">
                <img src="../../../assets/img/海.png" alt="" /></div
            ></el-table-column>
            <el-table-column property="miao" label="描述" />
            <el-table-column
              property="name"
              label="作者"
              show-overflow-tooltip
              width="200"
            />
            <el-table-column label="时间" property="color">
              <template #default="scope">{{ scope.row.time }}</template>
            </el-table-column>
            <el-table-column
              property="address"
              label="操作"
              show-overflow-tooltip
            >
              <div class="cao">
                <span class="cao-bian" @click="shan(list.id)">编辑</span>
                &emsp;
                <span class="cao-shan" @click="openFullScreen2">删除</span>
              </div>
            </el-table-column>
          </el-table>
          <div class="demo-pagination-block">
            <el-pagination
              :page-size="pageSize"
              layout="prev, pager, next, jumper"
              :total="leng.length"
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              v-model="currentPage"
            >
            </el-pagination>
          </div>
        </div>
      </el-col>
    </el-row>
    <el-pagination
      layout="prev, pager, next, jumper"
      :total="leng.length"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      v-model="currentPage"
      :page-size="pageSize"
    >
    </el-pagination>
  </div>
</template>

<script lang="ts">
import { defineComponent, onMounted, ref } from "vue";
import { ElLoading } from "element-plus";
import { mockapi } from "../../../api/zixun/mockwen";

interface type {
  name: string;
  time: number;
  pic: string;
}
export default defineComponent({
  setup() {
    const list = ref<type[]>([]);
    const currentPage = ref<any>(1);
    const pageSize = ref(3);
    const leng = ref<type[]>([]);
    onMounted(() => {
      wenlist();
    });
    const wenlist = async () => {
      const res = await mockapi.getServerList(
        currentPage.value,
        pageSize.value
      );
      list.value = res.result;
      const resn = await mockapi.getwenzhen();
      leng.value = resn.result.data;
    };
    const currentPage3 = ref("");

    const shan = (id: any) => {
      return (list.value = list.value.filter((item: any) => item.id !== id));
    };
    const handleSizeChange = (val: any) => {
      console.log(`${val} items per page`);
    };
    const handleCurrentChange = (val: any) => {
      console.log(`current page: ${val}`);
      currentPage.value = val;
      wenlist();
    };

    const openFullScreen2 = () => {
      const loading = ElLoading.service({
        lock: true,
        text: "钉子户",
        background: "rgba(0, 0, 0, 0.7)",
      });
      setTimeout(() => {
        loading.close();
      }, 2000);
    };

    return {
      list,
      currentPage3,
      handleSizeChange,
      handleCurrentChange,
      openFullScreen2,
      shan,
      currentPage,
      pageSize,
      leng,
      wenlist,
    };
  },
});
</script>

<style lang="less" scoped>
.main {
  position: relative;
}
.bg-purple {
  width: 100%;
  background: #fff;
  box-shadow: 0px 0px 3px 5px rgba(153, 153, 153, 0.09);
  border-radius: 3px;
  overflow: auto;
  margin-top: 40px;
  .wen {
    width: 100%;
    height: 40px;
    line-height: 40px;
    border-bottom: 1px solid #e9e9e9;
    font-size: 13px;
    font-family: PingFang SC;
    font-weight: 600;
    color: #333333;
    padding-left: 20px;
  }
  .imgUrl {
    width: 230px;
    height: 115px;
    img {
      width: 100%;
      height: 100%;
    }
  }
  /deep/ .el-table .cell {
    text-align: center;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    width: 100%;
  }
  .cao-bian {
    color: #446ce3;
    cursor: pointer;
  }
  .cao-shan {
    color: #ff0000;
    cursor: pointer;
  }
  .el-pagination {
    display: flex;
    justify-content: center;
  }

  .grid-content {
    border-radius: 4px;
    min-height: 36px;
  }
}
</style>
